﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace DevCore.Utility
{
    /// <summary>
    /// 日期与时间相关操作
    /// </summary>
    public class DateTimeHelper
    {
        /// <summary>
        /// 得到一个日期是星期几的
        /// </summary>
        /// <param name="date">传入日期</param>
        /// <returns></returns>
        public static String GetWeek(DateTime curDate)
        {
            Calendar myCal = CultureInfo.InvariantCulture.Calendar;
            switch (myCal.GetDayOfWeek(curDate).ToString())
            {
                case "Sunday":
                    return "星期日";

                case "Monday":
                    return "星期一";

                case "Tuesday":
                    return "星期二";

                case "Wednesday":
                    return "星期三";

                case "Thursday":
                    return "星期四";

                case "Friday":
                    return "星期五";

                case "Saturday":
                    return "星期六";
            }
            return "";
        }

        /// <summary>
        /// 得到当前的月份,例如:01
        /// </summary>
        /// <param name="curDate">日期</param>
        /// <returns></returns>
        public static String GetMonth(DateTime curDate)
        {
            int month = curDate.Month;
            string sMonth = month < 10 ? "0" + month : month.ToString();

            return sMonth;
        }

        /// <summary>
        /// 返回"01"这样的天
        /// </summary>
        /// <param name="curDate"></param>
        /// <returns></returns>
        public static String GetDay(DateTime curDate)
        {
            int day = curDate.Day;
            string sday = day < 10 ? "0" + day : day.ToString();
            return sday;
        }
    }
}
